//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>
#include <elatypes.h>

EXTERN_C int CDECL memcmp(const void *s1, const void *s2, size_t n)
{
//BUGBUG:comment for bug 8270
//#ifdef _GNUC
//
//#if defined(_x86)
//    int temp0, temp1, temp2;
//    register int result;
//
//    ASM("repe;"
//        "cmpsb;"//result=s2-s1(Intel INSTRUCTION SET REFERENCE tells that)
//                //see: CMPS/CMPSB/CMPSW/CMPSD-Compare String Operands
//                //result=src1(s2=esi)-src2(s1=edi)
//        "movl $1, %3;"
//        "je 1f;"//if s1==s2(ZF==0), goto 1: edx=edx-1
//        "js 2f;"//if s1>s2(s2-s1<0, SF==1)
//        "decl %3;"//otherwise(SF==0), -1 twice to make edx=-1
//        "1:"
//        "decl %3;"
//        "2:"
//        :"=D" (temp0), "=S" (temp1), "=c" (temp2), "=d" (result)
//        :"0" (s1), "1" (s2), "2" (n));
//    return result;
//#endif    //if defined(_x86)
//
//#endif    //ifdef _GNUC

    if (n != 0) {
        register const uchar_t *p1 = (const uchar_t *)s1;
        register const uchar_t *p2 = (const uchar_t *)s2;

        do {
            if (*p1++!= *p2++) {
                return (*--p1 - *--p2);
            }
        } while (--n != 0);
    }
    return (0);
}
